//
//  XNBaseTableViewController.swift
//  weibo
//
//  Created by 王向宁 on 16/5/21.
//  Copyright © 2016年 王向宁. All rights reserved.
//

import UIKit

class XNBaseTableViewController: UITableViewController,XNVisitorLoginViewDelegate {
    
    var userLogin = XNUserAccountViewModel.sharedAccountViewModel.userLogin
    
    //添加访客视图的属性
    lazy var visitorLoginView: XNVisitorLoginView = XNVisitorLoginView()
    
    //1.在loadView方法会自动检测根视图是否为nil,如果为nil就会调用loadView方法
    //2.在view没有实例化之前,不要调用view的get方法
    //3.loadView方法,是苹果专门为手写代码准备的,一旦实现了这个方法,并且没有super   xib/sb 就会自动失效
    
    //重写loadView
    
    override func loadView() {
        if userLogin {
            super.loadView()
        } else {
            self.loadVisitorView()
        }
    }
    
    private func loadVisitorView() {
        view = visitorLoginView
        
        visitorLoginView.visitorDelegate = self
    
    }
    
    //MARK实现协议方法
    func userWillLogin() {
        print("登录")
        
        let oauth = XNOAuthViewController()
        
        //内嵌到导航视图控制器
        let nav = UINavigationController(rootViewController: oauth)
        
        presentViewController(nav, animated: true, completion: nil)
    }
    
    func userWillRegister() {
        print("注册")
    }
    

    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }



}
